import frappe
from frappe import _

@frappe.whitelist()
def get_item_custom_field(doctype=None, txt=None, searchfield=None, start=None, page_len=None, filters=None):
    
    filters = {
        'dt': 'Item',
        'fieldtype': ('in', ['Data', 'Link', 'Select', 'Small Text', 'Dynamic Link']),        
    }
    or_filters = {}
    if txt:
        or_filters['label'] = ('like', f'%{txt}%')
        or_filters['fieldname'] = ('like', f'%{txt}%')
    data = frappe.get_all('Custom Field', filters = filters, or_filters = or_filters, fields = ["name", "fieldname", "label"], as_list=1)
    # 翻译标签
    data = [[d[0], d[1], _(d[2])] for d in data]
    
    return data